<template>
    <view class="affair_detail">
        <view class="nav" :style="{ background: showBg ? '#333' : '' }">
            <global-nav-bar type="black" left-icon="back" :color="showBg ? '#fff' : '#333'" :title="navBarTitle"
                :fixed="false" :isLeftBackShow="isLeftBackShow" backgroundColor="rgba(0, 0, 0, 0)"></global-nav-bar>
        </view>
        <view>
            <image class="bg"
                src="https://592800-erised-fresh.oss-cn-shenzhen.aliyuncs.com/upload/20221012/cdbdb2f4d67c21d9e1e8089234d17085.png"
                mode="" v-if="!showBg"></image>
        </view>
        <!-- 头部进度条 -->
        <view class="header">
            <elevtor-card :msg="{
                ...elevatorDetail,
                elevatorId: this.elevatorId,
                isFull: this.isFull,
            }">
            </elevtor-card>
            <!-- 切换状态 -->
            <view @click.prevent="changeState" class="statusArea" :style="{
                color: elevatorDetail.isStop == 1 ? '#0091ff' : '#E02020',
                zIndex: showBg ? 110 : 120,
            }" v-if="status == 3">{{ elevatorDetail.isStop == 1 ? "正常运行" : "停梯" }}
                <image v-if="elevatorDetail.isStop == 1" class="statusSwich" src="@/static/images/blue.png" mode="">
                </image>
                <image v-if="elevatorDetail.isStop == 2" class="statusSwich" src="@/static/images/red.png" mode="">
                </image>
            </view>
        </view>
        <view class="addressBox">
            <view class="addressBox_left">
                <view class="top">
                    <view class="name">
                        <image src="@/static/images/index/buildIcon.svg" mode=""></image>
                        <view>{{ elevatorDetail.buildingName }}</view>
                    </view>
                </view>
                <view class="buildAddress" @click.stop="petName(elevatorDetail)" v-if="
                    elevatorDetail.relationAlias && elevatorDetail.relationAlias.length
                ">
                    <view class="buildings">项目别名:{{
                        elevatorDetail.relationAlias.map((item) => item.alias).join(",")
                        }}</view>
                    <view>
                        <uni-icons :type="popupShow ? 'arrowup' : 'arrowdown'" size="14" color="#999;"></uni-icons>
                    </view>
                </view>
                <view class="buildAddress" @click.stop="toProjectDetail">{{
                    elevatorDetail.buildingAddress
                    }}</view>
            </view>
            <view class="addressBox_right">
                <view class="gpsAndCall">
                    <view class="gpsAndCall_item" @click.stop="handleCall(0)" v-if="
                        elevatorDetail.estateUserList &&
                        elevatorDetail.estateUserList.length
                    ">
                        <image src="@/static/images/phone3.png" mode=""></image>
                        <view>物业</view>
                    </view>
                    <view class="gpsAndCall_item guide" @click.stop="handleGuide">
                        <image src="@/static/images/locations.png" mode=""></image>
                        <view>导航</view>
                    </view>
                    <view class="line" v-if="
                        elevatorDetail.estateUserList &&
                        elevatorDetail.estateUserList.length
                    "></view>
                </view>
            </view>
        </view>
        <view class="content_box" :style="{ zIndex: showBg ? '100' : '105' }">
            <view class="progressBar">
                <view class="progressBar_content">
                    <view class="progressBar_item">
                        <stautsStep :actIndex="[-1, 0, 1, 2, -1, -1, -1][status - 1]" :list="options" :log="logs">
                        </stautsStep>
                    </view>
                    <view class="userListBox" @click="goTaskSetpPage">
                        <user-list lable="执行人员" :list="planDetail.users"></user-list>
                    </view>
                </view>
            </view>
            <view class="content_item">
                <view class="title">任务信息</view>
                <view class="falutItem">
                    <view class="label">紧急程度</view>
                    <text class="tag" v-for="(item, index) in btnBoxList" :key="index"
                        :style="{ color: item.color, borderColor: item.color, }"
                        v-if="workOrderDetail.emerProcType == item.key">
                        {{ item.label }}
                    </text>
                </view>
                <view class="des">
                    <view class="label">计划执行时间</view>
                    <text>{{ workOrderDetail.planDate || "-" }}</text>
                </view>
                <view class="des">
                    <view class="label">计划截止时间</view>
                    <text>{{ workOrderDetail.planFinishDate ? workOrderDetail.planFinishDate.split(' ')[0] + ' 23:59:59'
                        : "-" }}</text>
                </view>
                <view class="des">
                    <view class="label">转派截止时间</view>
                    <text>{{ workOrderDetail.redeployFinishDate || "-" }}</text>
                </view>
            </view>

            <view class="content_item" v-if="openData.updateTime">
                <view class="title flex">
                    <view>工单重新打开</view>
                    <view class="logTime">{{ openData.updateTime }}</view>
                </view>
                <view class="logDesc">{{ openData.recordLog }}</view>
            </view>
            <view class="content_item" v-if="closeData.updateTime">
                <view class="title flex">
                    <view>工单关闭</view>
                    <view class="logTime">{{ closeData.updateTime }}</view>
                </view>
                <view class="logDesc">{{ closeData.recordLog }}</view>

            </view>

            <!-- 最近一次保养 -->
            <view class="content_item" v-if="workOrderDetail.lastPlan">
                <last-record :msg="{ ...workOrderDetail.lastPlan, ...elevatorDetail }"
                    :isCorrection="true"></last-record>
            </view>

            <view class="content_item">
                <view class="title" style="padding: 0;">整改事项</view>
                <view class="temp-list" v-for="(item, index) in workOrderDetail.fromHistoryList" :key="index">
                    <view class="top">
                        <view class="indexNumber">
                            {{ index + 1 }}
                        </view>
                        <view style="font-weight: 500;">{{ item.tltNames || item.locationTypeName }}</view>
                        <view @click="updateShow(item)" style="margin-left: auto;color: #0091FF;">{{ item.historyShow ?
                            '收起' : '展开' }}历史记录</view>
                    </view>


                    <view class="content" v-if="item.historyShow">
                        <view v-if="item.signImg">
                            <view>{{ item.requireDesc || '打卡记录' }}</view>
                            <view style="display: flex;align-items: center;display: flex;flex-wrap: wrap;">
                                <view v-for="(it, idx) in item.signImg.split(',')" :key="idx"
                                    style="margin-top: 16rpx;margin-right: 16rpx;">
                                    <image @click="preViewFileJust(item.signImg.split(','), idx)" :src="it"
                                        :mode="'scaleToFill'" style="width: 112rpx;height: 112rpx;" />
                                </view>
                            </view>
                        </view>
                        <view v-else>
                            <conItemwork :disabled="true" @setNode="setNodeEmit" @finish="finishFuc" :pictureDisable="1"
                                :planStatus="status" :isPlanStatus="isPlanStatus" :form="item" :planId="planId"
                                :idx="idx" @addrecord="addrecordFuc"></conItemwork>
                        </view>
                    </view>

                    <view class="content">
                        <view class="c_title">工作项问题</view>
                        <view style="margin-top: 16rpx;">{{ item.questionDesc }}</view>
                    </view>

                    <view class="content" :style="!item.finish && item.showTips ? 'background:#fff3f3' : ''"
                        v-if="item.recordData && status >= 3">
                        <view class="c_title">整改记录</view>
                        <template>
                            <view v-for="(it, idx) in item.afterHistoryList" :key="idx">
                                <conItemwork @setNode="setNodeEmit" @finish="finishFuc" :pictureDisable="1"
                                    @setShowTips="setShowTips($event, item)" :planStatus="status"
                                    :isPlanStatus="isPlanStatus" :form="it" :planId="planId" :idx="idx"
                                    @addrecord="addrecordFuc"></conItemwork>
                            </view>
                        </template>
                    </view>
                </view>
            </view>
        </view>
        <!-- 底部部分 -->

        <!-- 开始按钮放开 -->

        <view class="bottom" v-if="(status == 2 || (status !== 4 && userSignCount == 0))
        ">
            <view class="right flex">
                <view class="start flex" @click="handleStart">开始 </view>
            </view>
        </view>
        <!-- 状态是整改中且签到过展示以下按钮 -->
        <view class="bottom" v-if="showBtns && status >= 3 && userSignCount > 0">
            <view class="right flex">
                <!-- <view v-if="status == 1">
                    <view class="start flex disabled" v-if="status == 1">工单待审批</view>
                    <view class="start flex disabled" v-if="status == 5 || status == 6">工单已关闭</view>
                </view> -->

                <view class="repariing flex" v-if="status == 3 && userSignCount > 0">
                    <view @click="handleFinsh(true)" v-if="userSignCount != 0">
                        <view class="add"> 完成任务 </view>
                    </view>
                </view>
                <view class="start flex disabled" v-if="status === 4">
                    <view class="finBtn">已完成</view>
                </view>
            </view>
        </view>

        <!-- 电梯状态弹窗 -->
        <model title="请选择电梯状态" :maskClick="false" @cancle="cancleChange" @comfire="comfireChange"
            :visible="visibleEleStatus">
            <view class="change_elevator">
                <view @click="changeElevator(1)" :class="elevatorStatus === 1 ? 'actElevator' : ''">正常运行</view>
                <view @click="changeElevator(2)" :class="elevatorStatus === 2 ? 'actElevator' : ''">停梯</view>
            </view>
        </model>

        <!-- 弹窗提示 -->
        <model title="完成提示" comfireTxt="确定" :maskClick="false" @cancle="visibleShow = false" @comfire="finishComfire"
            :visible="visibleShow">
            <view class="comfireBox">
                <view>是否完成任务</view>
                <view class="content">注:提交任务后任务记录不可修改</view>
            </view>
        </model>

        <!-- 提示上次签到弹框 -->
        <model :title="signType == 'in' ? '签到拍照提示' : '签退拍照提示'" :maskClick="false" @cancle="comfireUseLastImg(false)"
            @comfire="comfireUseLastImg(true)" :visible="visibleShowTwo">
            <view class="lastImg">
                {{
                    `是否使用上次${signType == "in"
                        ? workOrderDetail.lastSignImg && workOrderDetail.lastSignImg.signTime
                        : workOrderDetail.lastSignImg && workOrderDetail.lastSignImg.signOutTime
                    }【${signType == "in"
                        ? workOrderDetail.lastSignImg && workOrderDetail.lastSignImg.signTypeStatusDesc
                        : workOrderDetail.lastSignImg && workOrderDetail.lastSignImg.signOutTypeStatusDesc
                    }工单】的${signType == "in" ? "签到" : "签退"}拍照?`
                }}
            </view>
        </model>

        <!-- 物业电话 -->
        <property-phone ref="property" @bindClose="closePhone" :list="elevatorDetail.estateUserList"></property-phone>
        <aliasPopup :showAlias="popupShow" :aliasArr="aliasArr" @closedMask="closedMask"></aliasPopup>

        <view class="signCircle" v-if="status == 3 && userSignCount != 0"
            :style="{ left: movable.x + 'px', top: movable.y + 'px' }" @touchmove.stop="movableChange"
            @touchend="touchend">
            <view class="add" @click.stop="showStatusChangeBeforeLeave('')" v-if="isPlanStatus">签退</view>
            <view class="add" v-if="!isPlanStatus" @click="handleStart">{{ "继续" }}
            </view>
        </view>


        <aiResize ref="aiResize"></aiResize>
        <!-- 有未签退的工单 -->
        <model title="有未签退的整改工单" :maskClick="false" comfireTxt="去签退" width="500rpx" :showCloseIcon="false"
            @cancle="signOutModelVisible = false" @comfire="toNotSignOutOrder" :visible="signOutModelVisible">
            <not-sign-out-model :msg="checkCanSignOutMsg"></not-sign-out-model>
        </model>
        <previewMedia ref="previewMedia"></previewMedia>

        <recordDialog :planInfo="planInfo" :planId="planId" ref="recordDialog" @addRecord="finishAddRecord"
            :show="showRecordEdit" @closed="showRecordEdit = false"></recordDialog>

        <videoDialog ref="videoDialog" @closed="hideVideo" v-if="showVideo" :video="preVideo"></videoDialog>
    </view>
</template>

<script>
import videoDialog from './components/videoDialog.vue';
import stautsStep from '@/components/status-special/status-special.vue';
import ElevtorCard from './components/elevtor-card.vue';
import LastRecord from '@/components/last-record/last-record.vue';
import UserList from '@/components/user-list/user-list.vue';
import model from '@/components/model/index.vue';
import GlobalNavBar from '@/components/uni-nav-bar/global-nav-bar';
import PropertyPhone from '@/components/propertyPhone/index.vue';
import recordDialog from './components/recordDialog.vue';
import aiResize from '../components/ai-resize/ai-resize.vue';
import { getPlanDetail, getAllWorkItems, workItemUpdate, signIn, signOut } from '@/apis/workOrder.js';
import { getOffairDetail, finishOffair, getRecordnList } from '@/apis/correction.js';
import { getSelectWorkTracks } from '@/apis/taskStepPage.js';
import { mapState, mapActions } from 'vuex';
import {
    elevtorDetail,
    changeElevatorState,
    changeElevatorStoplog,
} from '@/apis/elevator.js';
// 经纬度距离计算
import { getDistance } from '@/utils/tools.js';
import { getlocalinfo } from '@/utils/utils.js';
import { timeUpdate, getConfig, checkCanSignOut } from '@/apis/sign.js';
import aliasPopup from '@/components/card-dial/aliasPopup.vue';
import NotSignOutModel from '../components/notSignOutModel/index.vue';

import conItemwork from './components/templateTree/conItemwork.vue';
export default {
    components: {
        GlobalNavBar,
        model,
        stautsStep,
        ElevtorCard,
        LastRecord,
        UserList,
        PropertyPhone,
        aliasPopup,
        NotSignOutModel,
        recordDialog,
        conItemwork,
        videoDialog,
        aiResize
    },
    data() {
        return {
            showchangeTips: false,
            // 顶部导航栏title
            navBarTitle: '',
            // 完成弹框
            visibleShow: false,
            // 详情
            f: {},
            signType: 'in',
            elevatorId: '',
            // 任务状态详情
            planDetail: {},
            // 我自己是否还未签退
            isPlanStatus: false,
            userSignCount: 0,
            showPoupup: false,
            options: [
                {
                    status: 2,
                    name: '待开始',
                    icon: '/static/images/step1.png',
                    createTime: '',
                },
                {
                    status: 3,
                    name: '整改中',
                    icon: '/static/images/step2.png',
                    createTime: '',
                },
                {
                    status: 4,
                    name: '已完成',
                    icon: '/static/images/step3.png',
                    createTime: '',
                },
            ],
            signinData: {},
            // signImg: [], // 签到图片
            status: '',
            elevatorDetail: {},
            elevatorStop: '',
            imgUrl: [],

            planId: '',
            lastPlan: {},
            showBg: false,
            imgaddress: '',
            stepList: [],
            isFull: false,
            logs: [],
            visibleShowTwo: false,
            // 改变电梯状态
            visibleEleStatus: false,
            elevatorStatus: 1,
            // 有同伴任务数据
            cantUsersArr: [],
            // 确定电梯状态后是否走签退逻辑
            showLeave: false,
            // 签退后是否走完成逻辑
            handFinish: false,

            // 是否填充照片
            useLastImg: false,
            config: {},
            // 24小时内是否可以编辑
            updateStatus: false,
            movable: {
                x: 320,
                y: 0,
                height: 0,
                width: 0,
            },
            emptyRecord: false,
            isLeftBackShow: true,
            // 区分按钮类型发送群消息
            buttonType: null,
            popupShow: false,
            aliasArr: [],
            signOutModelVisible: false,
            checkCanSignOutMsg: {},

            btnBoxList: [  // 紧急程度标签
                { color: '#0091FF', bgColor: '#dcf0ff', label: '较低', key: '4', },
                { color: '#F7B500', bgColor: '#fff7e1', label: '普通', key: '3', },
                { color: '#fa6400', bgColor: '#ffecdf', label: '紧急', key: '2', },
                { color: '#e02020', bgColor: '#ffecec', label: '非常紧急', key: '1', },
            ],

            openData: {}, // 重新打开数据
            closeData: {}, // 关闭数据
            workOrderDetail: {}, // 工单详情
            workerItemNodes: {},
            showRecordEdit: false,
            showVideo: false,
            preVideo: '',
            map: {},
            errorView: null,
            scrollTop: 0,
        };
    },

    async onLoad(e) {
        this.navBarTitle = '保养整改工单'
        this.planId = e.planId;
        this.elevatorId = e.elevatorId;

        await this.handleRreshToken();
        uni.$on('isFinsh', async (res) => {
            console.log(res, 'isFinsh');
            if (res === true) {
                // 完成
                this.finishComfire();
                await this.initData();
            }
        });
        uni.$on('openCamera', (data) => {
            this.openCamera(data);
        });
    },
    onUnload() {
        // 关闭页面前清除全局事件监听
        uni.$off('isFinsh');
        uni.$off('openCamera');
        uni.$off('preViewVideo');
        uni.$off('scrollToView');
        uni.$off('workitemUpdate' + this.planId);
        uni.$off('setNode' + this.planId);
    },
    async onShow() {
        await this.handleRreshToken();
        if (!this.userinfo.user_id) {
            uni.showModal({
                title: '提示',
                content: '检测到您未登录或登录已失效，请前往登录后在操作',
                showCancel: false,
                success: () => {
                    uni.navigateTo({
                        url: '../login/index',
                    });
                },
            });
            return;
        }
        await this.initData();
        // 判断是否已关闭和不是执行人
        // 判断工单是否是执行人
        // console.log(this.status, "status的值");
        let user = this.workOrderDetail.maintainUserList || [];
        let isIncludes = user.findIndex(
            (item) => item.userId == this.userinfo.user_id
        );
        // console.log(user, "user得知", isIncludes);
        let type = 1;
        if (this.status == 7 || isIncludes == -1) {
            console.log('看看这里');
            if (isIncludes == -1) {
                type = 2;
            }
            if (this.status == 7 && isIncludes == -1) {
                type = 1;
            }
        }
    },
    mounted() {
        wx.getSystemInfo({
            success: (res) => {
                console.log('system', res);
                this.movable.height = res.windowHeight - 100;
                this.movable.y = res.windowHeight - 240;
                this.movable.width = res.windowWidth;
                this.movable.x = this.movable.width - 55;
            },
        });
    },
    watch: {

    },
    computed: {
        ...mapState('user', ['userinfo']),
        planInfo() {
            return {
                buildingId: this.elevatorDetail.buildingId,
                buildingName: this.elevatorDetail.buildingName,
                elevatorId: this.elevatorDetail.id,
                elevatorAddress: this.elevatorDetail.elevatorAddress,
                planId: this.planId,
                planWorkItemId: '',
                partsId: '',
            };
        },
        showBtns() {
            let next = false;
            if (!this.planDetail.users) {
                return next;
            }
            for (let i = 0; i < this.planDetail.users.length; i++) {
                if (this.planDetail.users[i].userId == this.userinfo.user_id) {
                    next = true;
                    break;
                }
            }
            return next;
        },
    },
    onPageScroll(e) {
        this.scrollTop = e.scrollTop;
        if (e.scrollTop > 20) {
            this.navBarTitle = this.elevatorDetail.elevatorAddress;
            this.showBg = true;
            this.scrollTop = e.scrollTop;
        } else {
            this.navBarTitle = '保养整改工单'
            this.showBg = false;
        }
    },
    methods: {
        ...mapActions('user', ['handleRreshToken']),
        // 水印相机打开钩子
        openCamera(data) {
            let params = [];
            if (data) {
                for (const key in data) {
                    if (data[key]) {
                        params.push(`${key}=${data[key]}`);
                    }
                }
            }
            uni.navigateTo({
                url: '/pages/camera/camera' + (params.length ? `?${params.join('&')}` : ''),
                fail: (err) => {
                    console.log(err);
                },
            });
        },
        addrecordFuc(form) {
            if (!this.$refs['recordDialog']) {
                return;
            }

            this.showRecordEdit = true;
            this.$nextTick(() => {
                this.$refs['recordDialog'].initData(form);
            });
        },
        // 完成添加工作项描述记录
        finishAddRecord() {
            this.getDetail();
        },
        setNodeEmit(res) {
            if (res && !res.templateContentId) {
                res.templateContentId = '-1';  // 任务追踪
            }
            if (res && res.templateContentId) {
                this.workerItemNodes[res.templateContentId] = res.node;
            }
        },
        setShowTips(res, row) {
            row.finish = res.finish;
            row.showTips = res.showTips;
        },
        finishFuc(d) {
            let tid = d.tltId;
            // 已完成工作项
            let map = JSON.parse(JSON.stringify(this.map));
            if (map[tid] && map[tid].length > 0) {
                const idx = this.map[tid].indexOf(d.id);
                if (d.finish) {
                    if (idx == -1) {
                        this.map[tid].push(d.id);
                    }
                } else {
                    if (idx != -1) {
                        this.map[tid].splice(idx, 1);
                    }
                }
            } else {
                if (d.finish) {
                    this.map[tid] = [d.id];
                }
            }

            let tid1 = 'suc' + d.tltId;
            // 正常
            if (map[tid1] && map[tid1].length > 0) {
                for (let i = 0; i < map[tid1].length; i++) {
                    if (map[tid1][i] == d.id) {
                        if (d.finish && d.userChoose == 0) {

                        } else {
                            this.map[tid1].splice(i, 1);
                        }
                        break;
                    }
                    if (map[tid1].length - 1 == i && map[tid1][i] != d.id) {
                        if (d.finish && d.userChoose == 0) {
                            this.map[tid1].push(d.id);
                        }
                    }
                }
            } else {
                if (d.finish) {
                    this.map[tid1] = [d.id];
                }
            }

            console.log(`[Sida] uni.emit: Type${this.planId}`);

            this.$forceUpdate();
        },
        // 遍历工作项，触发每个工作项的校验
        callWorkerItemNodes() {
            for (const key in this.workerItemNodes) {
                this.workerItemNodes[key].watchFinish({ view: this.errorView });
            }
        },
        // 检查该工作项是否完成
        setFinishStatus(data) {
            let formData = JSON.parse(JSON.stringify(data));
            let finish = true;
            const type = formData.recordData.type;
            const item = formData.recordData;
            // formData.userRecordVOS = formData.userRecordVOS.filter(record => record.userId === this.userinfo.user_id);
            if (type == 1) {
                if (!item.userData || item.userChoose === undefined) {
                    finish = false;
                } else {
                    if (!item.userData.comparison) {
                        // 普通记录
                        if (
                            (item.userData.files.need && item.userData.files.must) ||
                            (item.userData.records.need && item.userData.records.must) ||
                            (item.userData.remarks.need && item.userData.remarks.must)
                        ) {
                            if (
                                !formData.userRecordVOS || formData.userRecordVOS.length == 0
                            ) {
                                finish = false;
                            } else {

                            }
                        }
                    } else {
                        // 保养前后记录

                        // 保养前
                        if (
                            (item.userData.filesBefore.need && item.userData.filesBefore.must) ||
                            (item.userData.recordsBefore.need && item.userData.recordsBefore.must) ||
                            (item.userData.remarksBefore.need && item.userData.remarksBefore.must)
                        ) {
                            if (
                                !formData.userRecordVOS ||
                                formData.userRecordVOS.length == 0
                            ) {
                                finish = false;
                            }
                            let before = false;
                            for (let n = 0; n < formData.userRecordVOS.length; n++) {
                                for (let f = 0; f < formData.userRecordVOS[n].recordVOList.length; f++) {
                                    if (formData.userRecordVOS[n].recordVOList[f].status == 2) {
                                        before = true;
                                        break;
                                    }
                                }
                                if (before) {
                                    break;
                                }
                            }
                            if (before == false) {
                                finish = false;
                            }
                        }

                        // 保养后
                        if (
                            (item.userData.filesAfter.need && item.userData.filesAfter.must) ||
                            (item.userData.recordsAfter.need && item.userData.recordsAfter.must) ||
                            (item.userData.remarksAfter.need && item.userData.remarksAfter.must)
                        ) {
                            if (
                                !formData.userRecordVOS ||
                                formData.userRecordVOS.length == 0
                            ) {
                                finish = false;
                            }
                            let after = false;
                            for (let n = 0; n < formData.userRecordVOS.length; n++) {
                                for (let f = 0; f < formData.userRecordVOS[n].recordVOList.length; f++) {
                                    if (formData.userRecordVOS[n].recordVOList[f].status == 3) {
                                        after = true;
                                        break;
                                    }
                                }
                                if (after) {
                                    break;
                                }
                            }
                            if (after == false) {
                                finish = false;
                            }
                        }
                    }
                }
            } else if (item.type == 2) {
                if (item.min > 0) {
                    let num = 0;
                    for (let j = 0; j < item.options.length; j++) {
                        if (item.options[j].val || item.options[j].val === 0 || item.options[j].val === '0') {
                            num++;
                        }
                    }
                    for (let j = 0; j < item.options.length; j++) {
                        let users = formData['userRecordVOS' + j] || {};
                        if (item.options[j].val || item.options[j].val === 0 || item.options[j].val === '0') {
                            if (item.options[j].result) {
                                let optionsItem = item.options[j];
                                let type = (optionsItem.val !== '' && optionsItem.inRangeSet && optionsItem.val >= Number(optionsItem.min) && optionsItem.val <= Number(optionsItem.max)) ? 'in' : 'out';
                                let json = item.options[j][type + 'Ranges'];

                                if (!json.comparison) {
                                    // 普通记录校验

                                    if (item.options[j][type] && (
                                        (json.files.need && json.files.must) ||
                                        (json.records.need && json.records.must) ||
                                        (json.remarks.need && json.remarks.must))
                                    ) {
                                        let isFinish = false;
                                        for (let key in users) {
                                            // 查询是否有当前用户并且符合类型的记录
                                            if (users[key].list[0].recordDataValue.type == type) {
                                                isFinish = true;
                                                break;
                                            }
                                        }
                                        console.log('isFinish', isFinish, users, item.options[j]);
                                        if (!isFinish) {
                                            finish = false;
                                            break;
                                        }
                                    }
                                } else {
                                    // 保养前后记录校验 
                                    if ((json.filesBefore.need && json.filesBefore.must) || (json.recordsBefore.need && json.recordsBefore.must) || (json.remarksBefore.need && json.remarksBefore.must)
                                    ) {
                                        let isFinish = false;
                                        for (let key in users) {
                                            // 查询是否有当前用户并且符合类型的记录
                                            for (let n = 0; n < users[key].list.length; n++) {
                                                if (users[key].list[n].status == 2) {
                                                    isFinish = true;
                                                    break;
                                                }
                                            }
                                        }

                                        if (!isFinish) {
                                            finish = false;
                                            break;
                                        }
                                    }

                                    if ((json.filesAfter.need && json.filesAfter.must) || (json.recordsAfter.need && json.recordsAfter.must) || (json.remarksAfter.need && json.remarksAfter.must)
                                    ) {
                                        let isFinish = false;
                                        for (let key in users) {
                                            // 查询是否有当前用户并且符合类型的记录
                                            for (let n = 0; n < users[key].list.length; n++) {
                                                if (users[key].list[n].status == 3) {
                                                    isFinish = true;
                                                    break;
                                                }
                                            }
                                        }

                                        if (!isFinish) {
                                            finish = false;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (num < item.min) {
                        console.log('完成的选项不足', item);
                        finish = false;
                    }
                }
            } else if (item.type == 3 || item.type == 4) {
                if (item.min > 0 && (!item.val || item.val.length < item.min)) {
                    finish = false;
                } else {
                    if (!item.options.comparison) {
                        // 普通记录 
                        if (
                            (item.options.files.need && item.options.files.must) ||
                            (item.options.records.need && item.options.records.must) ||
                            (item.options.remarks.need && item.options.remarks.must)
                        ) {
                            if (
                                !formData.userRecordVOS ||
                                formData.userRecordVOS.length == 0
                            ) {
                                finish = false;
                            }
                        }
                    } else {
                        // 保养前后记录验证
                        if ((item.options.filesBefore.need && item.options.filesBefore.must) || (item.options.recordsBefore.need && item.options.recordsBefore.must) || (item.options.remarksBefore.need && item.options.remarksBefore.must)) {
                            if (
                                !formData.userRecordVOS ||
                                formData.userRecordVOS.length == 0
                            ) {
                                finish = false;
                            } else {
                                let fin = false;
                                for (let n = 0; n < formData.userRecordVOS.length; n++) {
                                    for (let f = 0; f < formData.userRecordVOS[n].recordVOList.length; f++) {
                                        if (formData.userRecordVOS[n].recordVOList[f].status == 2) {
                                            fin = true;
                                            break;
                                        }
                                    }

                                    if (fin) {
                                        break;
                                    }
                                }
                                if (!fin) {
                                    finish = false;
                                }
                            }
                        }

                        if ((item.options.filesAfter.need && item.options.filesAfter.must) || (item.options.recordsAfter.need && item.options.recordsAfter.must) || (item.options.remarksAfter.need && item.options.remarksAfter.must)) {
                            if (
                                !formData.userRecordVOS ||
                                formData.userRecordVOS.length == 0
                            ) {
                                finish = false;
                            } else {
                                let fin = false;
                                for (let n = 0; n < formData.userRecordVOS.length; n++) {
                                    for (let f = 0; f < formData.userRecordVOS[n].recordVOList.length; f++) {
                                        if (formData.userRecordVOS[n].recordVOList[f].status == 3) {// 保养后
                                            fin = true;
                                            break;
                                        }
                                    }

                                    if (fin) {
                                        break;
                                    }
                                }
                                if (!fin) {
                                    finish = false;
                                }
                            }
                        }
                    }
                }
            }
            return finish;
        },
        // 检测到有未完成工作项 自动滚动到区域内
        scrollToViewFuc(res) {

            if (this.errorView) {
                // console.log('自动滚动到区域内',res)
                return;
            }
            this.isAllDone = false;
            this.errorView = res.workitem;

            console.log('自动滚动到区域内',
                res.workitem.name,
                res,
                res[0].top,
                this.scrollTop,
                res[0].top - 100 + this.scrollTop
            );

            // #ifdef MP-WEIXIN
            uni.pageScrollTo({
                scrollTop: res[0].top - 280 + this.scrollTop, // 滚动到页面节点的上边界坐标
                duration: 400, // 滚动动画的时长
            });
            // #endif

            // #ifdef H5  
            const element = document.getElementById(res[0].id);
            // console.log('自动滚动到区域内H5', element, res[0].id)
            if (element) {
                element.scrollIntoView({ behavior: 'smooth' });
            }
            // #endif
        },
        toNotSignOutOrder() {
            uni.navigateTo({
                url: `/subpages/correction/detail?planId=${this.checkCanSignOutMsg.planId}&elevatorId=${this.checkCanSignOutMsg.elevatorId}`,
            });
            this.signOutModelVisible = false;
        },
        updateShow(item) {
            item.historyShow = !item.historyShow
        },
        // 项目别名弹窗
        petName(obj) {
            this.popupShow = true;

            this.aliasArr = (obj.relationAlias || []).map((item) => item.alias);
        },
        closedMask() {
            this.popupShow = false;
        },
        movableChange(e) {
            // console.log('movableChange', e)
            let x = e.touches[0].pageX - 56 / 2;
            let y = e.touches[0].clientY - 56 / 2;
            if (x < 8) {
                x = 8;
            }
            if (x > 330) {
                x = 330;
            }
            if (y < 70) {
                y = 70;
            }
            if (y > this.movable.height + 5) {
                y = this.movable.height + 5;
            }
            this.movable.x = x;
            this.movable.y = y;
        },
        touchend() {
            if (this.movable.x < 156) {
                this.movable.x = 8;
            } else {
                this.movable.x = this.movable.width - 55;
            }
        },

        // 提交工作项数据
        workItemUpdate(formData) {
            const result = formData.recordData.userData ? formData.recordData.userData.result : '1';
            console.log('提交工作项数据', formData, result);
            // this.setOrgWorkItem(formData);

            // 检查该工作项是否完成
            return new Promise((resolve) => {
                workItemUpdate({
                    planId: formData.planId,
                    id: formData.childPlanCheckHistoryId,
                    result: result,
                    recordData: formData.recordData
                }).then((res) => {
                    resolve();
                }).catch(() => {
                });
            });
        },

        // 校验所有工作项
        getAllWorkItems() {
            const showTips = (str = '') => {
                uni.showToast({
                    title: str || '请完成必填记录的工作项',
                    icon: 'none',
                    mask: true,
                });
            };

            // 对操作记录 选项分组
            const groupByOptions = (arr) => {
                let map = {};
                for (let i = 0; i < arr.length; i++) {
                    for (let j = 0; j < arr[i].recordVOList.length; j++) {
                        let idx = arr[i].recordVOList[j].recordDataValue.index;
                        if (idx || idx === 0) {
                            if (map[idx]) {
                                map[idx].push(arr[i].recordVOList[j]);
                            } else {
                                map[idx] = [arr[i].recordVOList[j]];
                            }
                        }
                    }
                }
                return map;
            };
            return new Promise((resolve, reject) => {
                getAllWorkItems({
                    planId: this.planId,
                }).then((res) => {
                    let result = true;
                    try {
                        let list = res.data;
                        for (let i = 0; i < list.length; i++) {
                            if (list[i].templateContentId == '-1') { // 任务追踪
                                list[i].name = '任务追踪';
                                list[i].recordData = {
                                    type: "1", //工作项类型 1，2，3，4
                                    must: true, //必填
                                    comparison: false,// 数据对比（题型1）  true false
                                    options: [], //题目内容
                                    min: "", //最少填x项
                                    max: "", //最多填x项
                                    userChoose: 1,
                                    userData: {
                                        comparison: false,
                                        records: {
                                            need: false,
                                            must: false,
                                            val: "",
                                        },
                                        files: {
                                            need: true,
                                            must: true,
                                            val: "",
                                        },
                                        remarks: {
                                            need: true,
                                            must: true,
                                            val: "",
                                        }
                                    }
                                };
                            }
                            let item = list[i].recordData;
                            if (item.type == 1 && item.must) {
                                if (!item.userData) {
                                    // 如果没有选中 查询一下默认选中
                                    for (let j = 0; j < item.options.length; j++) {
                                        if (item.options[j].default) {
                                            item.userData = item.options[j];
                                            item.userChoose = j;
                                            break;
                                        }
                                    }
                                    if (!item.userData) {
                                        result = false;
                                        showTips();
                                        reject(item);
                                        return;
                                    }
                                }
                                console.log(111, (item.userData.files.need && item.userData.files.must) ||
                                    (item.userData.records.need && item.userData.records.must) ||
                                    (item.userData.remarks.need && item.userData.remarks.must));

                                if (
                                    (item.userData.files.need && item.userData.files.must) ||
                                    (item.userData.records.need && item.userData.records.must) ||
                                    (item.userData.remarks.need && item.userData.remarks.must)
                                ) {
                                    // 过滤掉他人的操作记录
                                    // list[i].userRecordVOS = list[i].userRecordVOS.filter(record => record.userId === this.userinfo.user_id);
                                    if (
                                        !list[i].userRecordVOS || list[i].userRecordVOS.length == 0
                                    ) {
                                        result = false;
                                        console.log('未完成', list[i]);
                                        // '项目：' + list[i].name + '需添加一条记录'
                                        showTips('请添加整改记录');
                                        reject(item);
                                        return;
                                    }
                                }
                                if (item.userData.comparison) {
                                    // 保养前
                                    if (
                                        (item.userData.filesBefore.need && item.userData.filesBefore.must) ||
                                        (item.userData.recordsBefore.need && item.userData.recordsBefore.must) ||
                                        (item.userData.remarksBefore.need && item.userData.remarksBefore.must)
                                    ) {
                                        if (
                                            !list[i].userRecordVOS ||
                                            list[i].userRecordVOS.length == 0
                                        ) {
                                            result = false;
                                            console.log('未完成', list[i]);
                                            // '项目：' + list[i].name + '需添加一条保养前记录'
                                            showTips('请添加整改记录');
                                            reject(item);
                                            return;
                                        }
                                        let before = false;
                                        for (let n = 0; n < list[i].userRecordVOS.length; n++) {
                                            for (let f = 0; f < list[i].userRecordVOS[n].recordVOList.length; f++) {
                                                if (list[i].userRecordVOS[n].recordVOList[f].status == 2) {
                                                    before = true;
                                                    break;
                                                }
                                            }
                                            if (before) {
                                                break;
                                            }
                                        }
                                        if (before == false) {
                                            result = false;
                                            console.log('未完成', item.userData, list[i]);
                                            // '项目：' + list[i].name + '需添加一条保养前记录'
                                            showTips('请添加整改记录');
                                            reject(item);
                                            return;
                                        }
                                    }

                                    // 保养后
                                    if (
                                        (item.userData.filesAfter.need && item.userData.filesAfter.must) ||
                                        (item.userData.recordsAfter.need && item.userData.recordsAfter.must) ||
                                        (item.userData.remarksAfter.need && item.userData.remarksAfter.must)
                                    ) {
                                        if (
                                            !list[i].userRecordVOS ||
                                            list[i].userRecordVOS.length == 0
                                        ) {
                                            result = false;
                                            console.log('未完成', list[i]);
                                            // '项目：' + list[i].name + '需添加一条保养后记录'
                                            showTips('请添加整改记录');
                                            reject(item);
                                            return;
                                        }
                                        let after = false;
                                        for (let n = 0; n < list[i].userRecordVOS.length; n++) {
                                            for (let f = 0; f < list[i].userRecordVOS[n].recordVOList.length; f++) {
                                                if (list[i].userRecordVOS[n].recordVOList[f].status == 3) {
                                                    after = true;
                                                    break;
                                                }
                                            }
                                            if (after) {
                                                break;
                                            }
                                        }
                                        if (after == false) {
                                            result = false;
                                            console.log('未完成', list[i]);
                                            // '项目：' + list[i].name + '需添加一条保养后记录'
                                            showTips('请添加整改记录');
                                            reject(item);
                                            return;
                                        }
                                    }
                                }
                            } else if (item.type == 2) {// 填空题
                                let optMap = groupByOptions(list[i].userRecordVOS || []);// 题型分组
                                if (item.min > 0) {
                                    let num = 0;
                                    for (let j = 0; j < item.options.length; j++) {
                                        if (item.options[j].val || item.options[j].val === 0) {
                                            num++;
                                        }
                                    }
                                    for (let j = 0; j < item.options.length; j++) {
                                        if (item.options[j].val || item.options[j].val === 0) {
                                            if (item.options[j].result) {
                                                let val = Number(item.options[j].val);
                                                let min = Number(item.options[j].min);
                                                let max = Number(item.options[j].max);
                                                let type = (val >= min && val <= max) ? 'in' : 'out';
                                                let json = item.options[j][type + 'Ranges'];
                                                if (!json.comparison) {
                                                    if (
                                                        (json.files.need && json.files.must) ||
                                                        (json.records.need && json.records.must) ||
                                                        (json.remarks.need && json.remarks.must)
                                                    ) {
                                                        let isFinish = optMap[j] && optMap[j].length ? true : false;

                                                        if (!isFinish) {
                                                            console.log('未完成', list[i], optMap, 1);
                                                            showTips(
                                                                '请添加整改记录'
                                                                // '填空：' + item.options[j].name + '需添加一条记录'
                                                            );
                                                            result = false;
                                                            reject(item);
                                                            return;
                                                        }
                                                    }
                                                }

                                                if (json.comparison && ((json.filesBefore.need && json.filesBefore.must) || (json.recordsBefore.need && json.recordsBefore.must) || (json.remarksBefore.need && json.remarksBefore.must))
                                                ) {
                                                    let isFinish = false;
                                                    for (let n = 0; n < optMap[j].length; n++) {
                                                        if (optMap[j][n].status == 2) {
                                                            isFinish = true;
                                                            break;
                                                        }
                                                    }

                                                    if (!isFinish) {
                                                        console.log('未完成', list[i], optMap, 2, json, j, type, item.options[j]);
                                                        showTips(
                                                            '请添加整改记录'
                                                            // '填空：' + item.options[j].name + '需添加一条保养前记录'
                                                        );
                                                        result = false;
                                                        reject(item);
                                                        return;
                                                    }
                                                }

                                                if (json.comparison && ((json.filesAfter.need && json.filesAfter.must) || (json.recordsAfter.need && json.recordsAfter.must) || (json.remarksAfter.need && json.remarksAfter.must))
                                                ) {
                                                    let isFinish = false;
                                                    for (let n = 0; n < optMap[j].length; n++) {
                                                        if (optMap[j][n].status == 3) {
                                                            isFinish = true;
                                                            break;
                                                        }
                                                    }
                                                    if (!isFinish) {
                                                        console.log('未完成', list[i], optMap, 3, json);
                                                        showTips(
                                                            '请添加整改记录'
                                                            // '填空：' + item.options[j].name + '需添加一条保养后记录'
                                                        );
                                                        result = false;
                                                        reject(item);
                                                        return;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    if (num < item.min) {
                                        console.log('未完成', list[i]);
                                        showTips(
                                            '请添加整改记录'
                                            // '项目：' + list[i].name + '至少填' + item.min + '项'
                                        );
                                        result = false;
                                        reject(item);
                                        return;
                                    }
                                }
                            } else if (item.type == 3 || item.type == 4) {
                                if (item.min > 0 && (!item.val || item.val.length < item.min)) {
                                    console.log('未完成', list[i]);
                                    showTips(
                                        '请添加整改记录'
                                        // '项目：' +
                                        // list[i].name +
                                        // '至少上传' +
                                        // item.min +
                                        // (item.type == 3 ? '张' : '个')
                                    );
                                    result = false;
                                    reject(item);
                                    return;
                                }

                                if (
                                    (item.options.files.need && item.options.files.must) ||
                                    (item.options.records.need && item.options.records.must) ||
                                    (item.options.remarks.need && item.options.remarks.must)
                                ) {
                                    if (
                                        !list[i].userRecordVOS ||
                                        list[i].userRecordVOS.length == 0
                                    ) {
                                        console.log('未完成', list[i]);
                                        showTips(
                                            '请添加整改记录'
                                            // '项目：' + list[i].name + '需添加一条记录'
                                        );
                                        result = false;
                                        reject(item);
                                        return;
                                    }
                                }

                                if (item.options.comparison && ((item.options.filesBefore.need && item.options.filesBefore.must) || (item.options.recordsBefore.need && item.options.recordsBefore.must) || (item.options.remarksBefore.need && item.options.remarksBefore.must))
                                ) {
                                    if (
                                        !list[i].userRecordVOS ||
                                        list[i].userRecordVOS.length == 0
                                    ) {
                                        console.log('未完成', list[i]);
                                        showTips(
                                            '请添加整改记录'
                                            // '项目：' + list[i].name + '需添加一条保养前记录'
                                        );
                                        result = false;
                                        reject(item);
                                        return;
                                    } else {
                                        let finish = false;
                                        for (let n = 0; n < list[i].userRecordVOS.length; n++) {
                                            for (let f = 0; f < list[i].userRecordVOS[n].recordVOList.length; f++) {
                                                if (list[i].userRecordVOS[n].recordVOList[f].status == 2) {
                                                    finish = true;
                                                    break;
                                                }
                                            }

                                            if (finish) {
                                                break;
                                            }
                                        }
                                        if (!finish) {
                                            console.log('未完成', list[i]);
                                            showTips(
                                                '请添加整改记录'
                                                // '项目：' + list[i].name + '需添加一条保养前记录'
                                            );
                                            result = false;
                                            reject(item);
                                            return;
                                        }
                                    }
                                }

                                if (item.options.comparison && ((item.options.filesAfter.need && item.options.filesAfter.must) || (item.options.recordsAfter.need && item.options.recordsAfter.must) || (item.options.remarksAfter.need && item.options.remarksAfter.must))
                                ) {
                                    if (
                                        !list[i].userRecordVOS ||
                                        list[i].userRecordVOS.length == 0
                                    ) {
                                        console.log('未完成', list[i]);
                                        showTips(
                                            '请添加整改记录'
                                            // '项目：' + list[i].name + '需添加一条保养后记录'
                                        );
                                        result = false;
                                        reject(item);
                                        return;
                                    } else {
                                        let finish = false;
                                        for (let n = 0; n < list[i].userRecordVOS.length; n++) {
                                            for (let f = 0; f < list[i].userRecordVOS[n].recordVOList.length; f++) {
                                                if (list[i].userRecordVOS[n].recordVOList[f].status == 3) {
                                                    finish = true;
                                                    break;
                                                }
                                            }
                                            if (finish) {
                                                break;
                                            }
                                        }
                                        if (!finish) {
                                            console.log('未完成', list[i]);
                                            showTips(
                                                '请添加整改记录'
                                                // '项目：' + list[i].name + '需添加一条保养后记录'
                                            );
                                            result = false;
                                            reject(item);
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    } catch (error) {
                        console.log('error', error);
                        result = false;
                        resolve(false);
                    }

                    resolve(result);
                });
            });
        },
        preViewFile(list, index) {
            let url = list.map((item) => {
                return { type: item.type, url: item.url };
            });
            this.$previewMedia({
                sources: url,
                current: index,
            });
        },
        // 预览
        preViewFileJust(list, index) {
            console.log('预览照片', list, index);
            let url = list.map((item) => {
                return { type: 'image', url: item };
            });
            this.$previewMedia({
                sources: url,
                current: index,
            });
        },
        // 跳转项目详情
        toProjectDetail() {
            uni.navigateTo({
                url:
                    '/pageModules/projectInfo/detail?id=' +
                    this.elevatorDetail.buildingId,
            });
        },
        // 修改电梯状态弹窗提示
        changeState() {
            if (this.status === 4) {
                uni.showToast({
                    title: '任务已完成',
                    icon: 'none',
                });
                return;
            }
            if (!this.isPlanStatus) {
                uni.showToast({
                    title: '请先签到开始,再进行操作',
                    icon: 'none',
                    mask: true,
                });
                return;
            }
            this.visibleEleStatus = true;
            // this.comfireChange();
        },
        cancleChange() {
            this.visibleEleStatus = false;
            this.elevatorStatus = this.elevatorDetail.isStop;
        },

        // 是否使用上次签到签退照片
        comfireUseLastImg(res) {
            console.log(this.handFinish, 8888);
            this.visibleShowTwo = false;
            this.useLastImg = res;
            let data = {
                signType: this.signType == 'in' ? 1 : 2,
                useLastImg: this.useLastImg,
                orderType: 9,
            };
            if (this.buttonType === 1) {
                data.buttonType = 1;
            }
            uni.setStorage({
                key: 'signObj',
                data,
            });

            uni.navigateTo({
                url: `/pages/sign/index?planId=${this.planId}&elevatorId=${this.elevatorId}&isFinsh=${this.handFinish}`,
            });
        },
        // 更改电梯状态
        changeElevator(nums) {
            this.elevatorStatus = nums;
        },
        // 电梯状态更改确定
        comfireChange() {
            uni.showLoading({
                title: '加载中',
                icon: 'none',
            });
            if (this.elevatorDetail.isStop === this.elevatorStatus) {
                // 选择同状态不请求
                uni.hideLoading();
                this.visibleEleStatus = false;
                if (this.showLeave) {
                    this.finishOut('');
                }
                return;
            }
            changeElevatorState({
                id: this.elevatorId,
                isStop: this.elevatorStatus,
            }).then(() => {
                this.visibleEleStatus = false;
                changeElevatorStoplog({
                    elevatorId: this.elevatorId,
                    initStatus: this.elevatorDetail.isStop,
                    setStatus: this.elevatorStatus,
                    module: `${this.planId}`,
                    position: 6,
                }).then(() => {
                    elevtorDetail({ elevatorId: this.elevatorId }).then((res) => {
                        if (res) {
                            uni.hideLoading();
                            uni.showToast({
                                title: '电梯状态切换成功',
                                icon: 'none',
                            });
                            this.elevatorDetail = res.data;
                            this.isFull = res.data.isFull;

                            if (this.showLeave) {
                                this.finishOut('');
                            }
                        }
                    });
                });
            });
        },

        // 获取任务跟踪进度条
        getSelectWorkTracks() {
            return new Promise((resolve) => {
                getSelectWorkTracks({ planId: this.planId }).then((res) => {
                    let workLogs = res.data.workLogs;
                    console.log(workLogs, '获取任务跟踪进度条');
                    let logs = [];
                    for (let i = 0; i < this.options.length; i++) {
                        let createTime = '';
                        // 当完成的记录条数小于等于重新打开时 过滤掉所有这俩个状态的记录  否则保留最后一条完成的记录
                        if (workLogs.filter(item => item.typeName === '任务完成').length <= workLogs.filter(item => item.typeName === '重新打开任务').length) {
                            workLogs = workLogs.filter(item => item.planStatus !== 4);
                        } else {
                            const lastCompletedIndex = workLogs.map(item => item.typeName).lastIndexOf('任务完成');
                            workLogs = workLogs.filter((item, index) => item.planStatus !== 4 || index === lastCompletedIndex);
                        }
                        for (let j = 0; j < workLogs.length; j++) {
                            if (workLogs[j].planStatus == this.options[i].status) {
                                createTime = workLogs[j].createTime;
                                break;
                            }
                        }
                        logs.push({ createTime });
                    }
                    this.logs = logs;
                    console.log(this.logs, '获取任务跟踪进度条');
                    resolve();
                });
            });
        },
        getPlanDetail() {
            return new Promise((resolve) => {
                getPlanDetail({ planId: this.planId }).then((res) => {
                    // console.log(res.data, "维保员列表");
                    this.planDetail = res.data;
                    this.isPlanStatus = this.setIsPlanStatus();
                    this.status = res.data.status;
                    this.getSelectWorkTracks();
                    // console.log(this.isPlanStatus, "this.isPlanStatus的值");
                    resolve();
                });
            });
        },
        // 我自己是否还未签退
        setIsPlanStatus() {
            if (!this.planDetail.users) {
                return false;
            }
            for (let i = 0; i < this.planDetail.users.length; i++) {
                if (
                    this.planDetail.users[i].userId == this.userinfo.user_id &&
                    this.planDetail.users[i].signUser
                ) {
                    this.userSignCount = this.planDetail.users[i].userSignCount;
                    return this.planDetail.users[i].signUser.isPlanStatus;
                }
            }
            this.userSignCount = 0;
            return false;
        },
        // 任务追踪页面
        goTaskSetpPage() {
            uni.navigateTo({
                url: `/pageModules/taskStepPage/taskStepPage?planId=${this.planId}&elevatorId=${this.elevatorId}&state=9`,
                fail: (err) => {
                    console.log(err);
                },
            });
        },
        updataShowFuc(val) {
            this.showPoupup = val;
        },
        handleBack() {
            uni.navigateBack({});
        },
        async initData() {
            uni.showLoading({
                title: '加载中',
                icon: 'none',
            });
            // 获取任务content详情
            await this.getPlanDetail();
            // 获取创建工单记录等记录
            await this.getDetail();
            // 获取配置
            await this.getConfig();
            elevtorDetail({ elevatorId: this.elevatorId }).then((res) => {
                if (res) {
                    console.log(res);
                    this.elevatorDetail = res.data;
                    this.elevatorStatus = res.data.isStop;
                    this.isFull = res.data.isFull;
                    // 设置水印缓存
                    let data = {
                        buildingId: this.elevatorDetail.buildingId,
                        buildingName: this.elevatorDetail.buildingName,
                        elevatorId: this.elevatorId,
                        elevatorAddress: this.elevatorDetail.elevatorAddress,
                        planId: this.planId,
                        planWorkItemId: '',
                        partsId: '',
                    };
                    uni.setStorage({
                        key: 'waterMarkMsg',
                        data,
                        success: (success) => {

                        },
                    });
                    uni.hideLoading();
                }
            });
            // 操作记录 包含重新打开和关闭
            getRecordnList({ planId: this.planId }).then(res => {
                console.log(res, "操作记录");
                this.openData = res.data.filter(item => item.recordType == 3)[0] || {};
                this.closeData = res.data.filter(item => item.recordType == 2)[0] || {};
            })
        },
        getDetail() {
            uni.showLoading({
                title: '加载中',
                icon: 'none',
            });
            return new Promise((resolve) => {
                getOffairDetail({ planId: this.planId }).then((res) => {
                    if (res) {

                        // 监听工作项点击查看作业指引
                        uni.$off('preViewVideo');
                        uni.$on('preViewVideo', (data = '') => {
                            this.preViewVideo(data);
                        });

                        // 监听滚动到区域内时间
                        uni.$off('scrollToView');
                        uni.$on('scrollToView', (data) => {
                            this.scrollToViewFuc(data);
                        });


                        // 工作项修改，同步数据
                        uni.$off('workitemUpdate' + this.planId);
                        uni.$on('workitemUpdate' + this.planId, (res) => {
                            this.workItemUpdate(res);// push工作项修改数据到远程 
                        });

                        // 存储所有工作项节点，方便提交时校验（h5）
                        uni.$off('setNode' + this.planId);
                        uni.$on('setNode' + this.planId, async (res) => {
                            this.setNodeEmit(res);
                        });

                        res.data.fromHistoryList.forEach(item => {
                            if (item.locationTypeName == '任务追踪') {
                                item.recordData = {
                                    type: "1", //工作项类型 1，2，3，4
                                    must: true, //必填
                                    comparison: false,// 数据对比（题型1）  true false
                                    options: [], //题目内容
                                    min: "", //最少填x项
                                    max: "", //最多填x项
                                    userChoose: 1,
                                    userData: {
                                        comparison: false,
                                        records: {
                                            need: false,
                                            must: false,
                                            val: "",
                                        },
                                        files: {
                                            need: true,
                                            must: true,
                                            val: "",
                                        },
                                        remarks: {
                                            need: true,
                                            must: true,
                                            val: "",
                                        }
                                    }
                                };
                            }
                            item.historyShow = false;
                            let arr = Object.values(
                                (item.checkRecords || []).reduce((acc, record) => {
                                    if (!acc[record.userId] || new Date(record.updateTime) > new Date(acc[record.userId].updateTime)) {
                                        acc[record.userId] = record;
                                    }
                                    return acc;
                                }, {})
                            );
                            item.userRecordVOS = [{
                                showAdd: arr[0] && arr[0].recordDataValue ? true : false,
                                userId: arr[0] ? arr[0].userId : '',
                                userName: arr[0] ? arr[0].recordUserName : '',
                                recordVOList: arr || []
                            }] || [];
                            item.afterHistoryList = [];
                            res.data.afterHistoryList.forEach(it => {
                                if (it.locationTypeName == '任务追踪') {
                                    it.recordData = {
                                        type: "1", //工作项类型 1，2，3，4
                                        must: true, //必填
                                        comparison: false,// 数据对比（题型1）  true false
                                        options: [], //题目内容
                                        min: "", //最少填x项
                                        max: "", //最多填x项
                                        userChoose: 1,
                                        userData: {
                                            comparison: false,
                                            records: {
                                                need: false,
                                                must: false,
                                                val: "",
                                            },
                                            files: {
                                                need: true,
                                                must: true,
                                                val: "",
                                            },
                                            remarks: {
                                                need: true,
                                                must: true,
                                                val: "",
                                            }
                                        }
                                    };
                                }

                                let list = Object.values(
                                    (it.checkRecords || []).reduce((acc, record) => {
                                        if (!acc[record.userId]) {
                                            acc[record.userId] = {
                                                userId: record.userId,
                                                userName: record.recordUserName,
                                                showAdd: record.recordDataValue ? true : false,
                                                recordVOList: []
                                            };
                                        }
                                        acc[record.userId].recordVOList.unshift(record);
                                        return acc;
                                    }, {})
                                );
                                it.userRecordVOS = list || [];
                                if (item.byScoreQuestionId == it.byScoreQuestionId) {
                                    item.afterHistoryList.push(it);
                                }
                            })
                        })

                        this.workOrderDetail = res.data;
                        console.log(res.data, "工单详情");

                        uni.hideLoading();
                    }
                    resolve(res.data.elevatorDetail);
                });
            });
        },
        preViewVideo(url = '') {
            if (typeof url != 'string') {
                return;
            }
            this.preVideo = url;

            this.showVideo = true;
        },
        // 获取经纬度信息
        getLocalInfo() {
            return new Promise((resolve) => {
                if (getApp().globalData.localinfo.latitude) {
                    if (
                        new Date().getTime() - getApp().globalData.localinfo.time <=
                        1000 * 60 * 2
                    ) {
                        resolve(getApp().globalData.localinfo);
                        return;
                    }
                }

                uni.getLocation({
                    type: 'gcj02',
                    success(res) {
                        console.log('位置信息获取成功', res);
                        getApp().globalData.localinfo = {
                            ...res,
                            time: new Date().getTime(),
                        };
                        resolve(res);
                    },
                    fail(err) {
                        console.log('位置信息获取失败', err);
                        resolve({});
                    },
                });
            });
        },

        // 签退前确定电梯状态
        showStatusChangeBeforeLeave(res, type) {
            let isFinsh = res ? true : false;
            this.handFinish = isFinsh;
            this.signType = 'out';
            const data = {
                signType: this.signType == 'in' ? 1 : 2,
                useLastImg: this.useLastImg,
                orderType: 9,
            };
            this.buttonType = type;
            if (type === 1) {
                // 区分按钮类型发送群消息
                data.buttonType = 1;
                this.buttonType = 1;
            }
            uni.setStorage({
                key: 'signObj',
                data,
            });
            if (this.config.affairSignOut == 1) {
                if (
                    this.workOrderDetail.lastSignImg &&
                    this.workOrderDetail.lastSignImg.signOutImage
                ) {
                    // 这里弹出弹框提示是否使用上次的照片
                    this.visibleShowTwo = true;
                } else {
                    uni.navigateTo({
                        url: `/pages/sign/index?planId=${this.planId}&elevatorId=${this.elevatorId}&isFinsh=${isFinsh}`,
                    });
                }
            } else {
                uni.navigateTo({
                    url: `/pages/sign/index?planId=${this.planId}&elevatorId=${this.elevatorId}&isFinsh=${isFinsh}`,
                });
            }
        },
        // 签退 post==> 是否签退后立即执行提交操作
        async finishOut() {
            console.log(post, '签退');
            const post = this.handFinish ? true : false;
            this.showLeave = false;
            let localInfo = await this.getLocalInfo();
            if (!localInfo.latitude) {
                uni.showModal({
                    title: '提示',
                    content: '请打开定位，再签退',
                    showCancel: false,
                });
                return;
            }
            // 计算是否范围内打卡
            let distance = getDistance(
                localInfo.latitude,
                localInfo.longitude,
                this.elevatorDetail.latitude,
                this.elevatorDetail.longitude
            );
            if (distance > this.$config.maxDistance) {
                uni.showModal({
                    title: '提示',
                    content: '当前不在项目位置,是否确定按照当前位置继续签退？',
                    success: (res) => {
                        if (res.confirm) {
                            this.signType = 'out';
                            this.signinData = { post: post || false };
                            this.imgaddress = '';
                            this.signImg = [];
                            this.$refs.popupSign.open('center');
                        }
                    },
                });

                return;
            }
            this.signType = 'out';
            this.imgaddress = '';
            this.signImg = [];
            this.signinData = {
                post: post || false,
            };
            this.$refs.popupSign.open('center');
            return;
        },

        // 签到按钮
        async signintime(e) {
            if (e != 1) {
                console.log('关闭');
                uni.hideLoading();
                this.imgaddress = '';
                this.signImg = [];
                this.$refs.popupSign.close('center');
                return;
            }
            let that = this;

            if (this.imgaddress) {
                await this.getPlanDetail();
                if (this.signType == 'in') {
                    if (this.status > 3 || this.isPlanStatus) {
                        uni.hideLoading();
                        uni.showModal({
                            title: '提示',
                            content: '签到失败，工单状态已改变',
                            showCancel: false,
                        });
                        return;
                    }
                }
                let localInfo = await this.getLocalInfo();
                console.log('localInfo', localInfo);
                let address = await getlocalinfo(
                    localInfo.latitude,
                    localInfo.longitude
                );
                let signStatus = 1;
                // 计算是否范围内打卡
                let distance = getDistance(
                    localInfo.latitude,
                    localInfo.longitude,
                    this.elevatorDetail.latitude,
                    this.elevatorDetail.longitude
                );
                if (distance > this.$config.maxDistance) {
                    signStatus = 2;
                }
                // uni.hideLoading()
                // return

                (this.signType == 'in' ? signIn : signOut)(
                    this.signType == 'in'
                        ? {
                            userId: that.userinfo.user_id,
                            planId: that.planId,
                            signImage: that.imgaddress,
                            signStatus: signStatus,
                            signLongitude: localInfo.longitude,
                            signLatitude: localInfo.latitude,
                            signAddress: address.result.address,
                        }
                        : {
                            userId: that.userinfo.user_id,
                            planId: that.planId,
                            signOutImage: that.imgaddress,
                            signOutStatus: signStatus,
                            signOutLongitude: localInfo.longitude,
                            signOutLatitude: localInfo.latitude,
                            signOutAddress: address.result.address,
                        }
                ).then(() => {
                    uni.hideLoading();
                    uni.showToast({
                        title: '提交成功',
                        icon: 'none',
                        mask: true,
                    });

                    setTimeout(async () => {
                        that.imgaddress = '';
                        that.imgUrl = [];
                        if (that.signinData.post && that.signType == 'out') {
                            console.log('立即执行提交');
                            // 立即执行提交
                            that.$refs.popupSign.close();
                            await that.initData();
                            that.handleFinsh(true);
                        } else {
                            that.$refs.popupSign.close();
                            that.initData();
                        }

                        if (this.signType == 'in') {
                            this.visibleShowTwo = true;
                        }
                    }, 700);
                });
            } else {
                uni.hideLoading();
                uni.showToast({
                    title: '请拍照',
                    icon: 'none',
                });
            }
        },

        // 验证是否有权限

        getPlanRole() {
            // console.log(this.planDetail);
            let next = false;
            if (!this.planDetail.users) {
                return next;
            }
            for (let i = 0; i < this.planDetail.users.length; i++) {
                if (this.planDetail.users[i].userId == this.userinfo.user_id) {
                    next = true;
                    break;
                }
            }
            if (!next) {
                uni.showModal({
                    title: '提示',
                    content: '你没有权限操作该任务',
                    showCancel: false,
                });
            }
            return next;
        },

        // 点击提交完成
        async finish() {
            if (this.getPlanRole() == false) {
                return;
            }

            uni.showLoading({
                title: '加载中',
                mask: true,
            });
            // 获取user的接口
            await this.getPlanDetail();
            let cantUsers = [];
            if (this.planDetail.users) {
                for (let i = 0; i < this.planDetail.users.length; i++) {
                    if (this.planDetail.users[i].userId == this.userinfo.user_id) {
                        if (
                            this.planDetail.users[i].signUser &&
                            this.planDetail.users[i].signUser.isPlanStatus
                        ) {
                            uni.hideLoading();
                            this.finishOut(1);

                            return;
                        }
                    } else {
                        if (
                            this.planDetail.users[i].signUser &&
                            this.planDetail.users[i].signUser.isPlanStatus
                        ) {
                            cantUsers.push(this.planDetail.users[i].userName);
                        }
                    }
                }
            }

            uni.hideLoading();
            if (cantUsers.length > 0) {
                uni.showModal({
                    title: '提示',
                    content: `同伴${cantUsers.join(
                        '、'
                    )}未签退，确定择强制完成，同伴自动签退；取消则等同伴签退`,
                    success: (res) => {
                        if (res.confirm) {
                            this.postPlan();
                        }
                    },
                });
                return;
            }
            this.postPlan();
        },
        // 提交任务
        async postPlan() {
            uni.hideLoading();
            let localInfo = await this.getLocalInfo();
            if (!localInfo.latitude) {
                uni.showModal({
                    title: '提示',
                    content: '请打开定位，再提交',
                    showCancel: false,
                });
                return;
            }
            uni.showModal({
                title: '提示',
                content: '提交任务后将不可修改，是否提交?',
                success: async (res) => {
                    if (res.confirm) {
                        uni.showLoading({
                            title: '提交中',
                            mask: true,
                        });
                        // 计算是否范围内打卡

                        finishOffair({
                            id: this.planId,
                        })
                            .then(() => {
                                uni.hideLoading();
                                uni.showToast({
                                    title: '提交成功',
                                });
                                setTimeout(() => {
                                    this.getPlanDetail();
                                    this.initElevtorDetail();
                                    this.initData();
                                }, 500);
                            })
                            .catch((res) => {
                                uni.hideLoading();
                                uni.showToast({
                                    title: res.msg,
                                    icon: 'none',
                                });
                                setTimeout(() => {
                                    this.initData();
                                }, 1000);
                            });
                    }
                },
            });
        },

        // 图片上传
        changeImg(list) {
            if (list.length > 0) {
                this.imgaddress = list[0];
                this.signImg = list;
            } else {
                this.signImg = list;
            }
        },
        async handleStart() {
            // 先查下工单状态
            await this.getPlanDetail();
            if (this.getPlanRole() == false) {
                return;
            }
            if (!this.showBtns) {
                uni.showModal({
                    title: '提示',
                    content: '你没有权限操作该任务',
                    showCancel: false,
                });
                return;
            }
            let date = new Date(this.planDetail.planDate.replace(/-/g, '/'));
            let now = new Date();
            now.setHours(0, 0, 0);
            console.log(now.getTime() + 1000 * 60 * 60 * 24 + 2000, date.getTime());
            if (date.getTime() > now.getTime() + 1000 * 60 * 60 * 24 - 2000) {
                uni.showModal({
                    title: '提示',
                    content: '任务未到可执行时间',
                    showCancel: false,
                });
                return;
            }
            let isAllow = await this.checkAllowSignFun();
            if (isAllow.isExist) {
                this.checkCanSignOutMsg = isAllow;
                this.signOutModelVisible = true;
                return;
            }

            // 如果设置需要拍照,再判断24小时内是否有签到照片
            // console.log(this.config, "config");
            // return
            this.handFinish = false;
            this.signType = 'in';
            // return;
            const data = {
                signType: this.signType == 'in' ? 1 : 2,
                useLastImg: this.useLastImg,
                orderType: 9,
            };
            uni.setStorage({
                key: 'signObj',
                data,
            });
            if (this.config.affairSigin == 1) {
                if (
                    this.workOrderDetail.lastSignImg &&
                    this.workOrderDetail.lastSignImg.signImage
                ) {
                    // 这里弹出弹框提示是否使用上次的照片
                    this.visibleShowTwo = true;
                } else {
                    uni.navigateTo({
                        url: `/pages/sign/index?planId=${this.planId}&elevatorId=${this.elevatorId}`,
                    });
                }
            } else {
                uni.navigateTo({
                    url: `/pages/sign/index?planId=${this.planId}&elevatorId=${this.elevatorId}`,
                });
            }
        },
        // 关闭提交按钮
        handleSubmit() {
            // this.showAddDialog=false
            this.$refs.popup.close();
            this.aa = '1';
            this.getDetail();
        },
        // 拨打电话
        handleCall() {
            this.$nextTick(() => {
                this.$refs.property.$refs.propertyPhone.open();
            });
        },
        closePhone() {
            this.$nextTick(() => {
                this.$refs.property.$refs.propertyPhone.close();
            });
        },

        // 确认完成按钮点击
        async finishComfire() {

            // 先查询下任务状态
            await this.getPlanDetail();
            // 先判断同伴签退没
            this.visibleShow = false;
            // 如果自己没有签退先去签退页面
            if (this.isPlanStatus) {
                setTimeout(() => {
                    this.handFinish = true;
                    this.showStatusChangeBeforeLeave(true, 1);
                }, 1000);
                return;
            }

            let cantUsers = [];

            if (this.planDetail.users) {
                for (let i = 0; i < this.planDetail.users.length; i++) {
                    if (this.planDetail.users[i].userId == this.userinfo.user_id) {
                        if (
                            this.planDetail.users[i].signUser &&
                            this.planDetail.users[i].signUser.isPlanStatus
                        ) {
                            uni.hideLoading();
                            this.handFinish = true;

                            this.showStatusChangeBeforeLeave(true);

                            return;
                        }
                    } else {
                        if (
                            this.planDetail.users[i].signUser &&
                            this.planDetail.users[i].signUser.isPlanStatus
                        ) {
                            cantUsers.push(this.planDetail.users[i].userName);
                        }
                    }
                }
            }
            // uni.hideLoading();
            this.cantUsersArr = cantUsers;
            console.log(this.cantUsersArr, '签退的人员');
            if (cantUsers.length > 0) {
                uni.showModal({
                    title: '提示',
                    content: `同伴${cantUsers.join(
                        '、'
                    )}未签退，确定择强制完成，同伴自动签退；取消则等同伴签退`,
                    success: async (res) => {
                        if (res.confirm) {
                            this.affairFinishPost();
                        }
                    },
                });
            } else {
                // 请求完成
                console.log('请求完成');
                this.affairFinishPost();
            }
        },

        // 整改完成
        async handleFinsh() {
            // 如果已完成return
            if (this.status === 4) {
                return;
            }
            this.errorView = null;
            this.callWorkerItemNodes();
            let result = await this.getAllWorkItems();
            if (!result) {
                return;
            }
            this.handFinish = false;
            this.visibleShow = true;
        },

        // 整改完成请求接口
        affairFinishPost() {
            console.log('请求完成');
            // return
            uni.showLoading({
                title: '提交中',
                mask: true,
            });
            /* 定位上报埋点*/
            this.reportAddress({
                userId: this.userinfo.user_id,
                operation: 5,
                planId: this.planId,
                recordType: 1,
            });
            /* 定位上报埋点 end*/

            finishOffair({ planId: this.planId }).then((res) => {
                if (res.data) {
                    this.initData();
                    uni.hideLoading();
                }
            });
        },

        // 多人维修检查状态
        handleDone() {
            // console.log("工单完成");
            uni.showToast({
                title: '工单状态已更新,请重新进入页面',
                icon: 'none',
            });
            setTimeout(() => {
                uni.navigateBack({});
            }, 500);
        },

        getAliasStr(str) {
            if (!str) {
                return '';
            }
            if (str.length > 20) {
                return '(项目别名：' + str.slice(0, 20) + '...)';
            } else {
                return '(项目别名：' + str + ')';
            }
        },
        // 导航
        handleGuide() {
            console.log(this.elevatorDetail, 6666);
            const {
                buildingName,
                relationAlias,
                latitude,
                longitude,
                buildingAddress,
            } = this.elevatorDetail;
            let alias = relationAlias;
            let aliasName = alias.length
                ? alias
                    .map((item) => {
                        return item.alias;
                    })
                    .join(',')
                : '';
            uni.getLocation({
                type: 'gcj02',
                success: () => {
                    console.log(latitude, longitude);
                    uni.openLocation({
                        latitude: Number(latitude),
                        longitude: Number(longitude),
                        scale: 18,
                        name: buildingName + this.getAliasStr(aliasName),
                        address: buildingAddress,
                        success: () => {
                            console.log('success');
                        },
                    });
                },
            });
        },
        getConfig() {
            return new Promise((resolve) => {
                getConfig().then((res) => {
                    if (res) {
                        this.config = res.data.config;
                        // console.log(this.config, "this.config");
                    }
                });
                resolve();
            });
        },
        checkAllowSignFun() {
            return new Promise((resolve) => {
                checkCanSignOut({ planId: this.planId }).then((res) => {
                    if (res) {
                        resolve(res.data);
                    }
                });
            });
        },
    },
};
</script>
<style>
page {
    height: 100%;
    background-color: #f3f6f8;
    font-size: 28rpx;
}
</style>

<style lang="scss" scoped>
$all_width: 96rpx;
$all_height: 96rpx;

.movable-area {
    height: 100vh;
    width: 750rpx;
    top: 0;
    position: fixed;
    z-index: 300;
    pointer-events: none; //此处要加，鼠标事件可以渗透

    .movable-view {
        width: $all_width;
        height: $all_height;
        pointer-events: auto; //恢复鼠标事件

        image {
            width: $all_width;
            height: $all_height;
        }
    }
}

.lastImg {
    padding: 30rpx 0 60rpx 0;
    text-indent: 2em;
}

.finishDateContent {
    display: flex;
    justify-content: space-between;
    padding-bottom: 24rpx;
    color: #666;
    border-bottom: 2rpx solid #e9e9e9;
    margin-bottom: 22rpx;

    .timeArea {
        display: flex;
        align-items: center;

        image {
            width: 32rpx;
            height: 32rpx;
        }
    }
}

.emptyBox {
    margin-left: 20rpx;
    margin-bottom: 38rpx;
}

.empty {
    flex-direction: column;
    border-radius: 8rpx;
    height: 172rpx;
    border: 2rpx solid #e9e9e9;
    padding-bottom: 30rpx;
}

.errorEmpty {
    border-color: #e02020;
}

.addressBox {
    width: 710rpx;
    margin: 0 auto;
    background: #fff;
    border-radius: 8rpx;
    font-size: 24rpx;
    padding: 20rpx 22rpx 16rpx 16rpx;
    font-size: 24rpx;
    color: #999;
    box-sizing: border-box;
    margin-bottom: 20rpx;
    // position: relative;
    // z-index: 110;
    display: flex;

    .top {
        display: flex;

        .name {
            display: flex;
            // padding-left: 14rpx;
            font-weight: 600;
            color: #333;
            align-items: center;
        }

        image {
            width: 32rpx;
            height: 32rpx;
            margin-right: 10rpx;
        }
    }

    .buildAddressBox {
        display: flex;
    }

    .buildAddress {
        padding: 6rpx 20rpx 0 32rpx;
        margin-left: 10rpx;
        width: 388rpx;
        margin-right: 30rpx;
        display: flex;
        align-items: center;
    }

    .addressBox_right {
        display: flex;
        flex: 1;
        justify-content: flex-end;

        align-items: center;
    }

    .gpsAndCall {
        position: relative;
        display: flex;
        align-items: center;
        width: 190rpx;
        color: #666;

        .gpsAndCall_item {
            display: flex;
            flex: 1;
        }

        .guide {
            justify-content: flex-end;
        }

        image {
            width: 32rpx;
            height: 32rpx;
        }

        .line {
            width: 2rpx;
            height: 24rpx;
            background: #e9e9e9;
            position: absolute;
            left: 50%;
            top: 6rpx;
        }
    }
}

.statusArea {
    padding: 10rpx 20rpx;
    background: #ffffff;
    border-radius: 8rpx;
    display: flex;
    font-size: 26rpx;
    position: absolute;
    font-weight: 500;
    right: 20rpx;
    top: 40rpx;
    z-index: 120;

    image {
        width: 32rpx;
        height: 32rpx;
    }
}

.affair_detail {
    .signCircle {
        height: 80rpx;
        width: 80rpx;
        display: flex;
        justify-content: center;
        align-items: center;
        background: #0091ff;
        color: #fff;
        position: fixed;
        z-index: 200;
        border-radius: 50%;
    }

    .nav {
        position: sticky;
        top: 0;
        z-index: 112;
    }

    .bg {
        width: 750rpx;
        height: 354rpx;
        position: absolute;
        top: 0;
    }

    .header {
        padding-left: 40rpx;
        padding-right: 32rpx;
        margin-bottom: 30rpx;
        padding-top: 28rpx;
        position: relative;
    }

    .progressBar_elevator {
        width: 710rpx;
        margin: 0 auto;
        background: #fff;
        border-radius: 8rpx;
        margin-bottom: 20rpx;
        display: flex;
        height: 84rpx;
        line-height: 84rpx;
        z-index: 300;

        view:nth-of-type(1) {
            flex: 1;
            font-size: 32rpx;
            font-weight: 500;
            color: #333333;
            margin-left: 20rpx;
        }

        view:nth-of-type(2) {
            flex: 0 0 200rpx;
            text-align: right;
            font-size: 26rpx;
            color: #0091ff;
            border-radius: 8rpx;
            padding: 0rpx 30rpx;
            vertical-align: middle;

            text {
                margin-right: 8rpx;
            }

            image {
                width: 32rpx;
                height: 32rpx;
                vertical-align: middle;
            }
        }
    }

    .content_box {
        padding: 0 20rpx;
        background-color: #f3f6f8;
        padding-bottom: 150rpx;
        position: relative;

        .userListBox {
            padding: 20rpx 0;
        }

        .content_item {
            margin-bottom: 20rpx;
            padding: 28rpx 20rpx;
            border-radius: 8rpx;
            background: #ffffff;

            .logDesc {
                color: #E02020;
                font-size: 28rpx;
            }

            .title {
                font-size: 32rpx;
                color: #333;
                font-weight: 600;
                padding-bottom: 22rpx;

                .logTime {
                    color: #999999;
                    font-size: 24rpx;
                    font-weight: normal;
                }
            }

            .flex {
                display: flex;
                justify-content: space-between;
                align-items: center;
            }

            .des {
                display: flex;
                margin-bottom: 16rpx;

                .label {
                    width: 240rpx;
                    margin-right: 16rpx;
                    color: #999;
                }

                :nth-child(2) {
                    display: flex;
                    flex: 1;
                    flex-wrap: wrap;
                }
            }

            .info-item {
                display: flex;
                align-items: center;
                font-size: 28rpx;
                color: #333;
                align-items: baseline;

                &-label {
                    width: 130rpx;
                    color: #999;
                    margin-right: 16rpx;
                }

                &-content {
                    flex: 1;
                    line-height: 35rpx;
                }

                &-word {
                    color: #0091ff;
                    flex: 1;
                    flex-direction: column;

                    .fileName {
                        width: 520rpx;
                        // background: pink;
                        white-space: nowrap;
                        overflow: hidden;
                        text-overflow: ellipsis;
                    }
                }
            }

            .imgs {
                width: 100%;
                display: flex;
                flex-wrap: wrap;

                image {
                    width: 113rpx;
                    height: 113rpx;
                    margin-right: 20rpx;
                    margin-top: 20rpx;
                }
            }

            .faultImg {
                display: flex;
                flex-wrap: wrap;

                image {
                    width: 120rpx;
                    height: 120rpx;
                    margin-right: 18rpx;
                }
            }

            .label {
                margin-right: 16rpx;
                color: #999999;
                font-size: 28rpx;
                width: 240rpx;
                // background: pink;
            }

            .falutItem {
                display: flex;
                align-items: center;
                margin-bottom: 16rpx;

                .tag {
                    border: 2rpx solid #0091ff;
                    border-radius: 8rpx;
                    padding: 4rpx 24rpx;
                    font-size: 26rpx;
                    color: #0091ff;
                }
            }

            .orderfalutDes {
                :nth-child(1) {
                    width: 200rpx;
                }

                margin-bottom: 40rpx;
            }
        }

        .record {
            padding-left: 0;

            .title {
                padding-left: 20rpx
            }
        }

        .temp-list {

            .top {
                display: flex;
                align-items: center;
                margin-top: 22rpx;


                .indexNumber {
                    background: #DDF0FF;
                    border-radius: 4rpx;
                    width: 40rpx;
                    height: 40rpx;
                    line-height: 40rpx;
                    text-align: center;
                    color: #0091FF;
                    font-size: 26rpx;
                    margin-right: 16rpx;
                }
            }

            .content {
                margin-top: 22rpx;
                background: #F6F7FA;
                padding: 16rpx 36rpx;
                border-radius: 8rpx;
                font-size: 28rpx;
                color: #333;

                .c_title {
                    font-weight: bold;
                    border-left: 4rpx solid #0091FF;
                    padding-left: 8rpx;
                    margin-left: -8rpx;
                }
            }
        }

        .progressBar {
            display: flex;
            justify-content: center;
            margin-bottom: 20rpx;

            .progressBar_content {
                width: 710rpx;
                // height: 284rpx;
                background: #ffffff;
                border-radius: 8rpx;
                padding: 24rpx 22rpx 0rpx 18rpx;
                box-sizing: border-box;
            }
        }
    }

    .bottom {
        position: fixed;
        bottom: 0;
        left: 0;
        z-index: 119;
        background-color: #fff;
        height: 100rpx;
        width: 100%;
        display: flex;
        border-top: 2rpx solid #eeeeee;
        box-sizing: border-box;
        padding: 0 20rpx;

        view {
            // height: 100%;
            display: flex;
            align-items: center;
        }

        .left {
            width: 200rpx;
            font-size: 20rpx;

            .left_item {
                display: flex;
                flex-direction: column;
                flex: 1;

                view {
                    width: 100%;
                    display: flex;
                    flex: 1;
                    justify-content: center;
                    // background: red;
                    color: #666;
                }

                image {
                    width: 48rpx;
                    height: 48rpx;
                }
            }
        }

        .right {
            flex: 1;

            .start {
                // width: 524rpx;
                height: 70rpx;
                background: #0091ff;
                border-radius: 8rpx;
                color: #fff;
                display: flex;
                flex: 1;

                .finBtn {
                    width: 100%;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                }
            }

            .disabled {
                color: #ccc;
                background: #EFEFEF;
            }

            .repariing {
                // width: 100%;
                display: flex;
                flex: 1;
                justify-content: space-between;
                align-items: center;

                view {
                    display: flex;
                    flex: 1;
                    justify-content: center;
                    height: 70rpx;
                    font-size: 26rpx;
                }

                .blue {
                    border-radius: 8rpx 0 0 8rpx;
                    color: #0091ff;
                    background: #f5fbff;
                }

                .add {
                    background: #0091ff;
                    color: #fff;
                    border-radius: 0 8rpx 8rpx 0;
                }

                .addRed {
                    position: relative;

                    text {
                        position: absolute;
                        top: -10rpx;
                        right: 0;
                        width: 30rpx;
                        height: 30rpx;
                        background: red;
                        border-radius: 15rpx;
                        font-size: 20rpx;
                        text-align: center;
                    }
                }

                .finish {
                    background: #efefef;
                    color: #cccccc;
                    font-size: 26rpx;
                }
            }
        }
    }

    .change_elevator {
        display: flex;
        flex-direction: row;
        justify-content: center;

        .actElevator {
            // background-color: #0091ff;
            font-size: 24rpx !important;
            color: #0091ff !important;
            border: 2rpx #0091ff solid !important;
        }

        view:nth-of-type(1) {
            // background-color: #0091ff;
            color: #666;
            height: 72rpx;
            width: 176rpx;
            line-height: 72rpx;
            text-align: center;
            border-radius: 8rpx;
            border: 2rpx #ccc solid;
            font-size: 24rpx;
            margin-right: 60rpx;
        }

        view:nth-of-type(2) {
            font-size: 24rpx;
            color: #666;
            height: 72rpx;
            width: 176rpx;
            line-height: 72rpx;
            text-align: center;
            border-radius: 8rpx;
            border: 2rpx #ccc solid;
        }
    }

    .comfireBox {
        text-align: center;

        .content {
            color: #e02020;
            padding-top: 10rpx;
            font-size: 24rpx;
        }
    }
}
</style>